<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:pe="http://primefaces.org/ui/extensions">
    <h:head>
        <title>#{bundle.savtrx}</title>
        <link href="./resources/css/default.css" rel="stylesheet" type="text/css" />
    </h:head>
    <h:body>
        <ui:composition >
            <h:form prependId="false" >
               
               <script type="text/javascript">  
                   var doInitForm=false;
                   var tofocus;
                   
                   function changeFocus(nextfcs) {tofocus=nextfcs;}
                   function setDoInitForm(st) {doInitForm=st;}
                   
                   function focusState(xhr, status, args) {  
                       if(args.validationFailed || !args.success) {}
                       else document.getElementById(tofocus).focus();
                       return false;
                   }
                   
                   function handleCompleteSaving(xhr, status, args) {  
                        if(args.validationFailed || !args.success) {
                            
                        }else 
                            setTimeout(function() {
                                if (doInitForm==true) btnNewSavtrx.jq.click();  
                            }, 3000);
                    }
                    
                    function customRK(e, id, nextfcs) {
                      var code = (e.keyCode ? e.keyCode : e.which);
                       if(code==13) {
                            
                            if (id=="savtrxAccntsrc") {
                                getAccntSrc();
                                tofocus=nextfcs;
                            
                            }else if (id=="savtrxAccntdest") {
                                getAccntDest();
                                tofocus=nextfcs;
                            }
                            
                            e.preventDefault ? e.preventDefault() : e.returnValue = false;
                            e.stopPropagation();
                        }
                    }
                </script>  
                
                <p:outputPanel autoUpdate="true">
                <p:toolbar >
                    <p:toolbarGroup align="left">
                        <p:commandButton  value="#{bundle.btnNew}" icon="ui-icon-document" widgetVar="btnNewSavtrx" 
                                          action="#{savtrxBean.newData()}"   oncomplete="setDoInitForm(false);"
                                         rendered="#{menuBean.cekButtonAccess(104,'INS;')}"
                                         update="savtrxDisplay" process="@this">
                            <pe:resetEditableValues for="savtrxDisplay" />  
                        </p:commandButton> 
                        
                        <p:commandButton id="submitSavtrx" value="#{bundle.btnSave}" icon="ui-icon-disk"
                                         actionListener="#{savtrxBean.trySave()}" update="savtrxDisplay" 
                                         rendered="#{menuBean.cekButtonAccess(104,'INS;')}" 
                                         oncomplete="setDoInitForm(true); handleCompleteSaving(xhr, status, args);" 
                                         disabled="#{!savtrxBean.editMode}" >
                        </p:commandButton> 
                    </p:toolbarGroup>
                    <p:toolbarGroup align="right">
                        <p:commandButton id="doNothingSavtrx" type="button" value="" style="width: 0px; height: 0px;"/> 
                         <p:defaultCommand target="#{savtrxBean.defaultButton}"/> 
                    </p:toolbarGroup>
                </p:toolbar>
                </p:outputPanel>

                <p:remoteCommand name="getAccntSrc" actionListener="#{savtrxBean.getSavingSrc('null')}" process="savtrxAccntsrc @this" 
                                 update="hideSavtrxSavaccntId savtrxAccntsrcInfo"  oncomplete="focusState(xhr, status, args);"/>
                <p:remoteCommand name="getAccntDest" actionListener="#{savtrxBean.getSavingDest('null')}" 
                                 process="savtrxAccntdest @this" update="hideSavtrxDestSavaccntId savtrxAccntdestInfo"  oncomplete="focusState(xhr, status, args);"/>
 
                <!-- LOOK UP CUSTOMER -->
                <p:dialog header="#{bundle.Select} #{bundle.accountNo}" widgetVar="dlgSavtrxLookupSav" closable="true" dynamic="true" >
                    <p:ajax listener="#{savtrxBean.handleCloseLookup}" />
                    <h:panelGrid id="displaySavtrxLookup" rendered="#{savtrxBean.showLookup==true}">
                        <ui:include src="../saving/searchSaving.xhtml" >
                            <ui:param name="lookupSavComponenId" value="savtrx" />
                        </ui:include> 
                        <h:panelGrid cellpadding="0" styleClass="pComBtnSTDR" >
                            <f:facet name="footer">
                                <p:commandButton value="#{bundle.btnOK}" icon="ui-icon-disk" 
                                                process="@this" update="savtrxAccntsrc hideSavtrxSavaccntId savtrxAccntsrcInfo"
                                                action="#{savtrxBean.getSavingSrc(searchSavingBean.selectedData.accountNo)}" 
                                                oncomplete="dlgSavtrxLookupSav.hide(); focusState(xhr, status, args);" />
                                <p:commandButton value="#{bundle.btnClose}" oncomplete="dlgSavtrxLookupSav.hide()" immediate="true" icon="ui-icon-document" process="@this" />
                            </f:facet>
                        </h:panelGrid>
                    </h:panelGrid>
                </p:dialog>
                
                <p:dialog header="#{bundle.Select} #{bundle.accountNo}" widgetVar="dlgSavtrxLookupSav2" closable="true" dynamic="true" >
                    <p:ajax listener="#{savtrxBean.handleCloseLookupDest}" />
                    <h:panelGrid id="displaySavtrxLookup2" rendered="#{savtrxBean.showLookupDest==true}">
                        <ui:include src="../saving/searchSaving.xhtml" >
                            <ui:param name="lookupSavComponenId" value="savtrx2" />
                        </ui:include> 
                        <h:panelGrid cellpadding="0" styleClass="pComBtnSTDR" >
                            <f:facet name="footer">
                                <p:commandButton value="#{bundle.btnOK}" icon="ui-icon-disk" 
                                                process="@this" update="savtrxAccntdest hideSavtrxDestSavaccntId savtrxAccntdestInfo" 
                                                action="#{savtrxBean.getSavingDest(searchSavingBean.selectedData.accountNo)}" 
                                                oncomplete="dlgSavtrxLookupSav2.hide(); focusState(xhr, status, args);" />
                                <p:commandButton value="#{bundle.btnClose}" oncomplete="dlgSavtrxLookupSav2.hide()" immediate="true" icon="ui-icon-document" process="@this" />
                            </f:facet>
                        </h:panelGrid>
                    </h:panelGrid>    
                </p:dialog>
                
                <h:panelGrid style="vertical-align: top" id="savtrxDisplay" 
                             cellpadding="" columns="3" 
                             columnClasses="panelGridId,panelGridId,panelGridId" >
                    <p:panel header="#{bundle.savtrx}">
                        <h:panelGrid columns="3" cellspacing="10" cellpadding="0">
                            <h:outputLabel value= "#{bundle.trxNum}" /><h:outputLabel value=":"/>
                            <h:outputText value="#{savtrxBean.savtrx.transferNo}" id="savtrxTransferNo" />

                            <h:outputLabel value= "#{bundle.date}" /><h:outputLabel value=":"/>
                            <h:outputText value="#{savtrxBean.savtrx.transDate}" id="savtrxdate" />

                            <p:outputLabel value= "#{bundle.fromAccnt}" for="savtrxAccntsrc" /><h:outputLabel value=":"/>
                            <h:panelGrid columns="3" cellpadding="0" cellspacing="0">
                                <p:inputText value="#{savtrxBean.savtrx.saving.accountNo}" style="width: 170px;"
                                        onkeydown="customRK(event, 'savtrxAccntsrc', '#{utilityBean.findClientId('savtrxAccntdest')}')" label="#{bundle.fromAccnt}" 
                                        id="savtrxAccntsrc" required="true" disabled="#{!savtrxBean.authorized}"
                                        requiredMessage="#{bundle.fromAccnt} #{bundle.requiredInput}" />

                                <p:commandButton icon="ui-icon-search" iconPos="center" styleClass="btnSmall"
                                                    update="displaySavtrxLookup" onclick="changeFocus('#{utilityBean.findClientId('savtrxAccntdest')}');"
                                                    process="@this" immediate="true" oncomplete="dlgSavtrxLookupSav.show();" disabled="#{!savtrxBean.authorized}" >
                                        <f:setPropertyActionListener target="#{savtrxBean.showLookup}" value="#{true}" />
                                </p:commandButton>
                            </h:panelGrid>

                            <p:outputLabel value= "#{bundle.toAccnt}" for="savtrxAccntdest"/><h:outputLabel value=":"/>
                            <h:panelGrid columns="3" cellpadding="0" cellspacing="0">
                                <p:inputText value="#{savtrxBean.accntDest}" style="width: 170px;"
                                        onkeydown="customRK(event, 'savtrxAccntdest', '#{utilityBean.findClientId('savtrxAmount')}')" label="#{bundle.toAccnt}" 
                                        id="savtrxAccntdest" required="true" disabled="#{!savtrxBean.authorized}"
                                        requiredMessage="#{bundle.fromAccnt} #{bundle.requiredInput}" />
                                <p:commandButton icon="ui-icon-search" iconPos="center" styleClass="btnSmall" process="@this" 
                                                    update="displaySavtrxLookup2" onclick="changeFocus('#{utilityBean.findClientId('savtrxAmount')}');"
                                                    immediate="true" oncomplete="dlgSavtrxLookupSav2.show();" disabled="#{!savtrxBean.authorized}" >
                                        <f:setPropertyActionListener target="#{savtrxBean.showLookupDest}" value="#{true}" />
                                </p:commandButton>
                            </h:panelGrid>

                            <p:outputLabel value= "#{bundle.amount}" for="savtrxAmount"/><h:outputLabel value=":"/>
                            <pe:inputNumber decimalSeparator="." thousandSeparator="," maxValue="999999999999999.99" minValue="0" 
                                value="#{savtrxBean.savtrx.amount}" style="width: 195px; text-align: right;"
                                    disabled="#{!savtrxBean.authorized}"
                                    id="savtrxAmount" required="true" label="#{bundle.amount}"
                                    requiredMessage="#{bundle.amount} #{bundle.requiredInput}">
                                    <p:ajax event="change" update="savtrxBalSrc,savtrxBalDest" 
                                            listener="#{savtrxBean.calcSaldoAhir()}" partialSubmit="false"/>
                            </pe:inputNumber>

                            <h:inputHidden value="#{savtrxBean.savtrx.destSavaccntId}" id="hideSavtrxDestSavaccntId"
                                required="true" requiredMessage="#{bundle.toAccnt} #{bundle.requiredInput}" />
                            
                            <h:inputHidden value="#{savtrxBean.savtrx.saving.savaccntId}" id="hideSavtrxSavaccntId"
                                required="true" requiredMessage="#{bundle.fromAccnt} #{bundle.requiredInput}" />
                            
                        </h:panelGrid>
                    </p:panel>
                    
                    <p:panel header="#{bundle.sourceAccount}" id="savtrxAccntsrcInfo" style="margin: 0 0 0 0;">
                        <h:panelGrid columns="3" border="0" cellpadding="0" cellspacing="10">
                            <h:outputLabel value= "#{bundle.savingNo}" /><h:outputLabel value= ":" />
                            <h:outputLabel value="#{savtrxBean.savtrx.saving.accountNo}" />
                            
                            <h:outputLabel value= "#{bundle.cif}" /><h:outputLabel value= ":" />
                            <h:outputLabel value="#{savtrxBean.savtrx.saving.customer.cif}" />

                            <h:outputLabel value= "#{bundle.globalName}" /><h:outputLabel value= ":" />
                            <h:outputText value="#{savtrxBean.savtrx.saving.customer.customerName}" />

                            <h:outputLabel value= "#{bundle.savprod}" /><h:outputLabel value= ":" />
                            <h:outputText rendered="true" value="#{savtrxBean.savtrx.saving.savprod.productName}" />

                            <h:outputLabel value= "#{bundle.saldoAwal}" /><h:outputLabel value= ":" />
                            <h:outputText styleClass="numPos" value="#{savtrxBean.savtrx.saving.balance}" >
                                <f:convertNumber groupingUsed="true" />
                            </h:outputText>
                            
                            <h:outputLabel value= "#{bundle.balance}" /><h:outputLabel value= ":" />
                            <p:outputPanel autoUpdate="true">
                            <h:outputText styleClass="numPos" value="#{savtrxBean.balanceSrc}" id="savtrxBalSrc">
                                <f:convertNumber groupingUsed="true" />
                            </h:outputText>
                            </p:outputPanel>
                            
                            <h:outputLabel value= "#{bundle.specimen}" /><h:outputLabel value=":"/>
                            <p:graphicImage  value="/upload/personal/#{savtrxBean.savtrx.saving.customer.specimen}" />
                            
                        </h:panelGrid>
                    </p:panel>
                    
                    <p:panel header="#{bundle.destAccount}" id="savtrxAccntdestInfo" style="margin: 0 0 0 0;">
                        
                        <h:panelGrid columns="3" border="0" cellpadding="0" cellspacing="10">
                            <h:outputLabel value= "#{bundle.savingNo}" /><h:outputLabel value= ":" />
                            <h:outputLabel value="#{savtrxBean.savdest.accountNo}" />
                            
                            <h:outputLabel value= "#{bundle.cif}" /><h:outputLabel value= ":" />
                            <h:outputLabel value="#{savtrxBean.savdest.customer.cif}" />

                            <h:outputLabel value= "#{bundle.globalName}" /><h:outputLabel value= ":" />
                            <h:outputText value="#{savtrxBean.savdest.customer.customerName}" />

                            <h:outputLabel value= "#{bundle.savprod}" /><h:outputLabel value= ":" />
                            <h:outputText rendered="true" value="#{savtrxBean.savdest.savprod.productName}" />

                            <h:outputLabel value= "#{bundle.saldoAwal}" /><h:outputLabel value= ":" />
                            <h:outputText styleClass="numPos" value="#{savtrxBean.savdest.balance}" >
                                <f:convertNumber groupingUsed="true" />
                            </h:outputText>
                            
                            <h:outputLabel value= "#{bundle.balance}" /><h:outputLabel value= ":" />
                            <p:outputPanel autoUpdate="true">
                            <h:outputText styleClass="numPos" value="#{savtrxBean.balanceDest}" id="savtrxBalDest">
                                <f:convertNumber groupingUsed="true" />
                            </h:outputText>
                            </p:outputPanel>
                            
                            <h:outputLabel value= "#{bundle.specimen}" /><h:outputLabel value=":"/>
                            <p:graphicImage  value="/upload/personal/#{savtrxBean.savdest.customer.specimen}" />
                            
                        </h:panelGrid>
                    </p:panel>
                    
                </h:panelGrid>

            </h:form>
        </ui:composition> 
    </h:body>
</html>

